<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="approvalFinishList" @selection-change="handleSelectionChange">
      <el-table-column label="培训方式" align="center" prop="trainMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.train_method" :value="scope.row.trainMethod"/>
        </template>
      </el-table-column>
      <el-form-item label="培训类型" prop="trainType">
          <el-select v-model="form.trainType" placeholder="请选择培训类型">
            <el-option
              v-for="dict in dict.type.train_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-table-column label="培训班课时" align="center" prop="trainPeriod" />
        <el-table-column label="课程表(附件)" align="center" prop="urlClassTable" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlClassTable" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="报名册(附件)" align="center" prop="urlApplication" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlApplication" :width="50" :height="50"/>
        </template>
      </el-table-column>

      <el-table-column label="签到表(附件)" align="center" prop="urlSign" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlSign" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="培训评估报告(附件)" align="center" prop="urlInvalue" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlInvalue" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="安全培训合格证明(附件)" align="center" prop="urlCertificate" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.urlCertificate" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="成绩汇总表" align="center" prop="gradeSet" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.gradeSet" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="考场情况记录表" align="center" prop="examplaceRecord" width="120">
        <template slot-scope="scope">
          <image-preview :src="scope.row.examplaceRecord" :width="50" :height="50"/>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            style="width: 40px;"
            @click="checkInformation(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="primary"
            style="width: 80px; margin-top: 5px;"
            @click="checkStudentInformation(scope.row)"
          >查看学生信息</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改审批完成信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form :inline="true" ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="培训方式" prop="trainMethod">
          <el-select v-model="form.trainMethod" placeholder="请选择培训方式">
            <el-option
              v-for="dict in dict.type.train_method"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="培训类型" prop="trainType">
          <el-select v-model="form.trainType" placeholder="请选择培训类型">
            <el-option
              v-for="dict in dict.type.train_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="培训课时" prop="trainPeriod">
          <el-input v-model="form.trainPeriod" placeholder="请输入培训课时" />
        </el-form-item>
        <el-form-item  label="签到表(附件)" prop="urlSign">
          <image-upload v-model="form.urlSign"/>
          </el-form-item>

          <el-form-item  label="培训评估报告(附件)" prop="urlInvalue">
            <image-upload v-model="form.urlInvalue"/>
          </el-form-item>

          <el-form-item  label="安全培训合格证明(附件)" prop="urlCertificate">
            <image-upload v-model="form.urlCertificate"/>
          </el-form-item>

          <el-form-item label="成绩汇总表" prop="gradeSet">
          <image-upload v-model="form.gradeSet"/>
        </el-form-item>
        <el-form-item label="考场情况记录表" prop="examplaceRecord">
          <image-upload v-model="form.examplaceRecord"/>
        </el-form-item>
        <el-form-item label="培训计划申请" prop="trainplanApplication">
          <file-upload v-model="form.trainplanApplication"/>
        </el-form-item>
        <el-form-item label="考试申请表pdf" prop="examApplicationPdf">
          <file-upload v-model="form.examApplicationPdf"/>
        </el-form-item>
        <el-form-item label="合格证明表pdf" prop="examCertificatePdf">
          <file-upload v-model="form.examCertificatePdf"/>
        </el-form-item>
        <el-form-item label="办证申请表pdf" prop="certApplicationPdf">
          <file-upload v-model="form.certApplicationPdf"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listApprovalFinish, getApprovalFinish, delApprovalFinish, addApprovalFinish, updateApprovalFinish, checkFinishInformation } from "@/api/approvalFinish/approvalFinish";

export default {
  name: "ApprovalFinish",
  dicts: ['train_method', 'train_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 审批完成信息表格数据
      approvalFinishList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    // 查看学生信息
    checkStudentInformation(row) {
      window.location.href = "../finishStudent?certApplicationId=" + row.id;
    },
    // 查看详细信息
    checkInformation(row) {
      checkFinishInformation(row.id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看完整信息"
      })
    },
    /** 查询审批完成信息列表 */
    getList() {
      this.loading = true;
      listApprovalFinish(this.queryParams).then(response => {
        this.approvalFinishList = response.rows;
        console.log(this.approvalFinishList)
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sum: null,
        sendTime: null,
        approvalProcessSign: null,
        xzspjsprId: null,
        xzspjfzrId: null,
        gaizhang2Id: null,
        gaizhang2Picture: null,
        yingjifzrId: null,
        yingjizrId: null,
        gaizhang3Id: null,
        gaizhang3Picture: null,
        isDeleted: null,
        createId: null,
        createTime: null,
        updateId: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加审批完成信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getApprovalFinish(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改审批完成信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateApprovalFinish(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApprovalFinish(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除审批完成信息编号为"' + ids + '"的数据项？').then(function() {
        return delApprovalFinish(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('approvalFinish/approvalFinish/export', {
        ...this.queryParams
      }, `approvalFinish_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
